'use strict';

// 引入模块
let http = require('http');
let path = require('path');
let fs = require('fs');

let workPath = path.resolve('.')

let server = http.createServer((req, res) => {
    res.write('<head><meta charset="utf-8"/></head>');
 
    
    
    if (req.url !== '/favicon.ico') {  
      
        let reqPath = req.url;
        let fullPath = path.join(workPath, reqPath);
        let log = fs.readdirSync(fullPath);
        log.forEach(item => {
            if (item === 'index.html') {
                let fileName = path.join(fullPath, item);
                console.log(fileName);
                fs.createReadStream(fileName).pipe(res);
            }
        })
        console.log(fullPath);
    }

})
server.listen(3020);
console.log('Server running at http://127.0.0.1:3020/');